home *** CD-ROM | disk | FTP | other *** search
/ Languguage OS 2 / Languguage OS II Version 10-94 (Knowledge Media)(1994).ISO / gnu / oleo-1_4.lha / oleo-1.4 / global.h < prev    next >
C/C++ Source or Header  |  1993-03-15  |  6KB  |  222 lines

  1. #ifndef GLOBALH
  2. #define GLOBALH
  3.  
  4. /*    Copyright (C) 1990, 1992, 1993 Free Software Foundation, Inc.
  5.  
  6. This program is free software; you can redistribute it and/or modify
  7. it under the terms of the GNU General Public License as published by
  8. the Free Software Foundation; either version 2, or (at your option)
  9. any later version.
  10.  
  11. This program is distributed in the hope that it will be useful,
  12. but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  14. GNU General Public License for more details.
  15.  
  16. You should have received a copy of the GNU General Public License
  17. along with this software; see the file COPYING.  If not, write to
  18. the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.  */
  19.  
  20. #include "sysdef.h"
  21. #include "utils.h"
  22.  
  23.  
  24. #define RCFILE ".oleorc"
  25.  
  26. /* The most important compile-time constant.  How many bits do we want to
  27.    allocate for cell-references?  Useful values are 8 and 16 (at the moment)
  28.    8 allows luser to access 255*255 cells (probably big enough)
  29.    16 allows luser to access 65535*65535, which is more than will fit in
  30.    the avaliable virtual memory on any 32-bit machine.
  31.  */
  32.  
  33. #ifndef BITS_PER_CELLREF
  34. #define BITS_PER_CELLREF 16
  35. #endif
  36.  
  37. /* The location of a cell that can never be referenced */
  38. #define NON_ROW        0
  39. #define NON_COL        0
  40.  
  41. #define MIN_ROW        1
  42. #define MIN_COL     1
  43.  
  44. #if BITS_PER_CELLREF==16
  45. typedef unsigned short CELLREF;
  46. #define CELLREF_MASK 0xFFFF
  47. #define MAX_ROW 65535
  48. #define MAX_COL 65535
  49.  
  50. /* Do *not* assume that 'name' is aligned!  It probably isn't */
  51. #define GET_ROW(name)        ((((name)[0])<<8)|(name)[1])
  52. #define GET_COL(name)        ((((name)[2])<<8)|(name)[3])
  53. #define PUT_ROW(name,val)    ((name)[0]=((val)>>8)),((name)[1]=val)
  54. #define PUT_COL(name,val)    ((name)[2]=((val)>>8)),((name)[3]=val)
  55. #define EXP_ADD            sizeof(CELLREF)*2
  56. #else
  57. #if BITS_PER_CELLREF==8
  58. typedef unsigned char CELLREF;
  59. #define CELLREF_MASK 0xFF
  60. #define MAX_ROW          255
  61. #define MAX_COL       255
  62.  
  63. #define GET_ROW(name)        ((name)[0])
  64. #define GET_COL(name)        ((name)[1])
  65. #define PUT_ROW(name,val)    ((name)[0]=(val))
  66. #define PUT_COL(name,val)    ((name)[1]=(val))
  67. #define EXP_ADD            sizeof(CELLREF)*2
  68. #else
  69. FOO FOO FOO You need to define the obvious macros above
  70. #endif
  71. #endif
  72.  
  73. /* Struct rng is used to describe a region of cells */
  74. struct rng
  75. {
  76.   CELLREF lr, lc, hr, hc;
  77. };
  78.  
  79. /* A ref_fm structure contains a list of all cells that reference some
  80.  * value.  The value can be another cell or some global (such as the system
  81.  * time).
  82.  *
  83.  * These structures are hash-consed and shared.  The hash-cons procedure
  84.  * will re-use a particular structure if there is only one reference to it.
  85.  */
  86. struct ref_fm
  87. {
  88.   struct ref_fm *refs_next;
  89.   unsigned short refs_refcnt;
  90.   unsigned short refs_used;
  91.   struct ref_array
  92.     {
  93.       CELLREF ref_row;
  94.       CELLREF ref_col;
  95.     } fm_refs[1];
  96. };
  97.  
  98. /* refs_to is a vector of locations in a formula where the
  99.  * cell references other cells, ranges, or variables 
  100.  */
  101. struct ref_to
  102. {
  103.   unsigned short refs_refcnt;
  104.   struct ref_to *refs_next;
  105.   unsigned short refs_used;
  106.   unsigned char to_refs[1];
  107. };
  108.  
  109. /* These macros are used to extract/store ranges in compiled formulas. */
  110. #define GET_RNG(name,putit)    bcopy((VOIDSTAR)(name),(VOIDSTAR)(putit),sizeof(struct rng))
  111. #define PUT_RNG(name,putit)    bcopy((VOIDSTAR)(putit),(VOIDSTAR)(name),sizeof(struct rng))
  112. #define EXP_ADD_RNG        sizeof(struct rng)
  113.  
  114. extern struct obstack tmp_mem;
  115. extern VOIDSTAR tmp_mem_start;
  116.  
  117. /* Defined in io-utils.c: */
  118. #define ERR_MAX        17
  119. extern char *ename[];
  120. extern char tname[];
  121. extern char fname[];
  122. extern char iname[];
  123. extern char mname[];
  124. extern char nname[];
  125.  
  126. extern VOIDSTAR parse_hash;
  127. extern double __plinf, __neinf, __nan;
  128.  
  129. /* These have two uses.  During parsing, these contain the 
  130.  * base address of all relative references.  During evaluation,
  131.  * these contain the address of the cell that is being updated.
  132.  * 
  133.  * When MY_CELL is set, these should be the address of that cell.
  134.  * The address is used to recompute MY_CELL as the sparse array moves 
  135.  * around.
  136.  * 
  137.  * Whey are all these distinct uses bound up in one pair of GLOBAL
  138.  * variables?  GOOD QUESTION?  Why didn't the person who created the mess at
  139.  * least toss in a COMMENT like the above to explain what was happening? 
  140.  * ANOTHER GOOD QUESTION!
  141.  */
  142. extern CELLREF cur_row, cur_col;
  143.  
  144. extern int default_jst;
  145. extern int default_fmt;
  146. extern int default_lock;
  147.  
  148. extern unsigned short current_cycle;
  149. extern int a0;
  150. extern int errno;
  151. extern const char oleo_version_string[];
  152.  
  153. #ifdef __STDC__
  154.  
  155. extern double astof (char **);
  156. extern long astol (char **);
  157. extern void free (void *);
  158. extern void panic (const char *, ...);
  159.  
  160. extern VOIDSTAR init_stack (void);
  161. extern void flush_stack (void *);
  162. extern void push_stack (void *, void *);
  163. extern VOIDSTAR pop_stack (void *);
  164. extern int size_stack (void *);
  165.  
  166. extern void add_ref (CELLREF, CELLREF);
  167. extern void add_range_ref (struct rng *);
  168. extern void add_timer_ref (int);
  169. extern void add_ref_to (int);
  170.  
  171. struct hash_control; /* in case it hasn't been declared yet */
  172. extern char *hash_insert (struct hash_control *, char *, VOIDSTAR);
  173. extern char *flt_to_str (double);
  174. extern void push_refs (struct ref_fm *);
  175. extern void no_more_cells (void);
  176.  
  177. extern char *range_name (struct rng *);
  178. extern char *cell_name (CELLREF, CELLREF);
  179.  
  180. extern char *new_value (CELLREF, CELLREF, char *);
  181.  
  182. extern unsigned char parse_cell_or_range (char **, struct rng *);
  183.  
  184. struct var; /* in case it hasn't been declared yet */
  185. extern void for_all_vars (void (*)(char *, struct var *));
  186. #else
  187.  
  188. extern double astof ();
  189. extern long astol ();
  190. extern void free ();
  191. extern void panic ();
  192.  
  193. extern VOIDSTAR init_stack ();
  194. extern void flush_stack ();
  195. extern void push_stack ();
  196. extern VOIDSTAR pop_stack ();
  197. extern int size_stack ();
  198.  
  199. extern void add_ref ();
  200. extern void add_range_ref ();
  201. extern void add_timer_ref ();
  202. extern void add_ref_to ();
  203.  
  204. extern char *hash_insert ();
  205.  
  206.  
  207. extern char *flt_to_str ();
  208. extern void push_refs ();
  209. extern void no_more_cells ();
  210.  
  211. extern char *range_name ();
  212. extern char *cell_name ();
  213.  
  214. extern char *new_value ();
  215.  
  216. extern unsigned char parse_cell_or_range ();
  217.  
  218. extern void for_all_vars ();
  219. #endif
  220.  
  221. #endif
  222.